package com.bootdo.cms.service.impl;

import com.bootdo.cms.dao.VideoDao;
import com.bootdo.cms.service.ChannelService;
import com.bootdo.cms.service.VideoService;
import com.bootdo.cms.domain.VideoDO;
import com.bootdo.common.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;


@Service
public class VideoServiceImpl implements VideoService {
	@Autowired
	private VideoDao videoDao;
	@Autowired
	private ChannelService channelService;
	
	@Override
	public VideoDO get(Long id){
		return videoDao.get(id);
	}
	
	@Override
	public List<VideoDO> list(Map<String, Object> map){
		String channelId = null;
		try {
			channelId = map.get("channelId").toString();
			if (StringUtils.isNotBlank(channelId)) {
				Long channelIdL = Long.valueOf(channelId);
				List<Long> childIds = channelService.listChildrenIds(channelIdL);
				childIds.add(channelIdL);
				map.put("channelId", null);
				map.put("channelIds",childIds);
			}
		} catch (Exception e) {
			System.out.println("channelId is Null!");
		}
		return videoDao.list(map);
	}
	
	@Override
	public int count(Map<String, Object> map){
		return videoDao.count(map);
	}
	
	@Override
	public int save(VideoDO video){
		return videoDao.save(video);
	}
	
	@Override
	public int update(VideoDO video){
		return videoDao.update(video);
	}
	
	@Override
	public int remove(Long id){
		return videoDao.remove(id);
	}
	
	@Override
	public int batchRemove(Long[] ids){
		return videoDao.batchRemove(ids);
	}
	
}
